Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
point /username to /[user]/[tab].js and not [user]/index.js in nextjs

I'm attempting to create a user profile page that generates content based on the current tab the user is in.

The tab is decided based on what is passed in the URL (e.g. /username/tab1). The only issue with this is that one of the valid tabs the user can visit actually has a blank value (/username, to get the default tab).

However, when you enter this into the browser, Next automatically assumes I want to retrieve /[user]/index.js (which doesn't exist), when in actuality what I want to get is /[user]/[tab].js and pass a blank value to the tab property in context.query.

Is this possible without creating a separate index.js and [tab].js file?

// Exported inside /pages/[user]/[tab].js
export const getServerSideProps = async (context) => {
    const { page, tab } = context.query;

    // When we're on /username/foo it should output "foo".
    // When we're on /username it should output "".
    console.log(tab); 
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can achieve this using an optional catch-all route.

So, rename your [tab].js as [[...tab]].js, so it will catch also the requests to /username without a tab. Then in your code you'll handle tab as optional.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda